To show Filedialogbox | |
---|---|
askdirectory(**options) | Will show a dialogbox to select directory |
askopenfilename(**options) | Will show a dialogbox to select file |
askopenfilenames(**options) | Will show a dialogbox to select multiple files |
asksaveasfilename(**options) | Will show a dialogbox to select /enter a file/filename |
Options | |
---|---|
title | a title for dialogbox. |
initialdir | a initial dir to be shown in dialog box. |
filetypes |
file filter for dialogbox For ex [('all files', '.*'), ('text files', '.txt'), (‘Images’,’.gif; .png)] |
from tkinter import * from tkinter.filedialog import * import import os def show(): ans=askdirectory(initialdir=os.getcwd(),title="select a folder:") print(ans) win=Tk() win.geometry("150x250") btn=Button(win,text="Show",command=show) btn.pack() win.mainloop()
from tkinter import * from tkinter.filedialog import * import os def show(): my_filetypes = [('all files', '.*'),('textfiles','.txt')] ans=askopenfilename(initialdir=os.getcwd(),filetypes=my_filetypes) print(ans) win=Tk() win.geometry("150x250") btn=Button(win,text="Show",command=show) btn.pack() win.mainloop()